.PYONY: protobuf, clean

srcDir = .
genDir = ./pb
protoc = protoc -I . -I ./googleapis
genGRPC = --go_out ${genDir} --go_opt paths=source_relative \
--go-grpc_out ${genDir} --go-grpc_opt paths=source_relative --go-grpc_opt require_unimplemented_servers=false
genGateway = --grpc-gateway_out ${genDir} --grpc-gateway_opt paths=source_relative
genOpenAPI = --openapiv2_out ${genDir} --openapiv2_opt use_go_templates=true

protobuf:
	@ln -fs ../googleapis
	@mkdir -p pb
	@${protoc} ${genGRPC} ${srcDir}/*.proto

	@${protoc} ${genGateway} ./${srcDir}/user_service.proto
	@${protoc} ${genOpenAPI} ./${srcDir}/user_service.proto
	@#sed -e '12a\"schemes": \["http", "https"\],' -i ${genDir}/user_service.swagger.json

	@${protoc} ${genGateway} ./${srcDir}/class_service.proto
	@${protoc} ${genOpenAPI} ./${srcDir}/class_service.proto
	@#sed -e '12a\"schemes": \["http", "https"\],' -i ${genDir}/class_service.swagger.json

	@${protoc} ${genGateway} ./${srcDir}/course_service.proto
	@${protoc} ${genOpenAPI} ./${srcDir}/course_service.proto
	@#sed -e '12a\"schemes": \["http", "https"\],' -i ${genDir}/course_service.swagger.json

	@${protoc} ${genGateway} ./${srcDir}/chapter_service.proto
	@${protoc} ${genOpenAPI} ./${srcDir}/chapter_service.proto
	@#sed -e '12a\"schemes": \["http", "https"\],' -i ${genDir}/chapter_service.swagger.json

	@${protoc} ${genGateway} ./${srcDir}/question_service.proto
	@${protoc} ${genOpenAPI} ./${srcDir}/question_service.proto
	@#sed -e '12a\"schemes": \["http", "https"\],' -i ${genDir}/question_service.swagger.json

	@${protoc} ${genGateway} ./${srcDir}/collecting_data_service.proto
	@${protoc} ${genOpenAPI} ./${srcDir}/collecting_data_service.proto
	@#sed -e '12a\"schemes": \["http", "https"\],' -i ${genDir}/collecting_data_service.swagger.json

clean:
	@rm -vf googleapis
	@rm -rvf pb
